package com.junjie.checkin.security.service;

import com.junjie.checkin.entity.TUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

/**
 * @author 洪浚杰
 * @description
 * @date 2025/6/9 12:55
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthDetails implements UserDetails {
    private TUser user;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if (user.getRole()!=1){
            return Arrays.asList(new SimpleGrantedAuthority("ROLE_user"));
        }
        else {
            return Arrays.asList(new SimpleGrantedAuthority("ROLE_admin"));
        }
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }
}
